package org.example.onetry.servlet;

import jakarta.servlet.GenericServlet;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import org.example.onetry.service.impl.serviced;
import org.example.onetry.service.studentservicec;
import org.example.onetry.user.users;

import java.io.IOException;
@WebServlet(urlPatterns = {"/cx"})
public class cx extends GenericServlet {
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
       /** response.setContentType("text/html");
        request.setCharacterEncoding("UTF-8");
**/
        studentservicec servived =new serviced();
        //使用session保存传递数据
        HttpSession session = request.getSession();
        /**if(session != null) {
                String use = (String) session.getAttribute("selct");
            if(use!=null)
                response.getWriter().println(use);
        }**/
        String user = (String) session.getAttribute("selct");
        //将传过来的字符串强转为整形
        int userid = Integer.parseInt(user);
        System.out.println(userid);
        users ca=servived.queryone(userid);
        /**
        if(ca != null) {
            response.getWriter().println("<table border=\"1\"cellspacing=\"0\" cellpadding=\"6\" >");
            response.getWriter().println("<tr>");
        response.getWriter().println("<td>"+ca.getId()+"</td>");
            response.getWriter().println("<td>"+ca.getNa()+"</td>");
            response.getWriter().println("<td>"+ca.getCon()+"</td>");
            response.getWriter().println("<td>"+"<a href='index.html'>"+"回到首页"+"</a></td>");
        response.getWriter().println("</tr>");
        response.getWriter().println("</table>");
        }
         **/
        //注销操作：在Session内清空User--->清空Session内的所有对象
        //request.getSession().invalidate();
/**
        //退回登陆
        response.sendRedirect("index.html");
**/
          request.setAttribute("ca",ca);
          request.getRequestDispatcher("queryaone.jsp").forward(request, response);

    }
}
